﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using FreightSoft.Models;

namespace FreightSoft.DataAccessLayer.ORDER
{
    public class CustomerOrderDAO
    {
        public void InsertCO(decimal orderId, decimal customerId, decimal priority, System.DateTime wantedDelDate, string deliveryAddress, string forwarder, string source, string destination)
        {
            using (var context = new Entities())
            {
                CUSTOMER_ORDER order = new CUSTOMER_ORDER();
                order.ORDER_ID = orderId;
                order.CUSTOMER_ID = customerId;
                order.PRIORITY = priority;
                order.WANTED_DELIVERY_DATE = wantedDelDate;
                order.DELIVERY_ADDRESS = deliveryAddress;
                order.FORWARDER_ID = forwarder;
                order.SOURCE = source;
                order.DESTINATION = destination;
                order.STATUS = "Planned";

                context.CUSTOMER_ORDER.Add(order);
                context.SaveChanges();
            }
        }

        public CUSTOMER_ORDER FindOrder(int orderId)
        {
            using (var context = new Entities())
            {
                var order = (from o in context.CUSTOMER_ORDER
                             where o.ORDER_ID == orderId
                            select o).First();

                return (CUSTOMER_ORDER)order;
            }
        }
        
        public void UpdateCO(decimal orderId, decimal customerId, decimal priority, System.DateTime wantedDelDate, string deliveryAddress, string forwarder, string source, string destination)
        {
            using (var context = new Entities())
            {
                var order = (from o in context.CUSTOMER_ORDER
                             where o.ORDER_ID == orderId
                             select o).First();
                                
                order.PRIORITY = priority;
                order.WANTED_DELIVERY_DATE = wantedDelDate;
                order.DELIVERY_ADDRESS = deliveryAddress;
                
                context.SaveChanges();
            }
        }

        //public List<CUSTOMER_ORDER> GetOrders()
        //{
        //    using (var context = new Entities())
        //    {
        //        var exams = (from e in context.Exams
        //                     select e).ToList();

        //        return (List<Exam>)exams;
        //    }
        //}
    }
}


        
        
        
        
        